Slice
从输入张量中提取一个子集(切片)。根据给定的起始索引(begin)和切片大小(size),在每个维度上截取数据。
\[output[i_0, i_1, \dots, i_{n-1}] = input[begin_0 + i_0, begin_1 + i_1, \dots, begin_{n-1} + i_{n-1}]\]
其中 $n$ 为维度数(ndim),且满足 $0 le i_k < size_k$。
- 输入:
input - 输入张量数据地址。
input_shape - 输入张量的形状数组地址。
ndim - 输入张量的维度数。
begin - 切片起始索引数组地址(长度为 ndim)。
size - 切片大小数组地址(长度为 ndim)。
core_mask(int, 可选) - 核掩码(仅适用于共享存储版本)。
- 输出:
output - 计算结果存储地址(输出张量形状即为 size)。
- 支持平台:
FT78NEMT7004
备注
FT78NE 支持 int8, int16, int32, fp32, fp64, cplx64, cplx128
MT7004 支持 fp16, fp32, int16, int32, cplx64
切片操作不改变数据数值,仅改变数据的空间排布,常用于特征提取或张量分解。
共享存储版本:
-
void i8_slice_s(int8_t *input, int8_t *output, int *input_shape, int ndim, int *begin, int *size, int core_mask)
-
void i16_slice_s(int16_t *input, int16_t *output, int *input_shape, int ndim, int *begin, int *size, int core_mask)
-
void i32_slice_s(int32_t *input, int32_t *output, int *input_shape, int ndim, int *begin, int *size, int core_mask)
-
void hp_slice_s(half *input, half *output, int *input_shape, int ndim, int *begin, int *size, int core_mask)
-
void fp_slice_s(float *input, float *output, int *input_shape, int ndim, int *begin, int *size, int core_mask)
-
void dp_slice_s(double *input, double *output, int *input_shape, int ndim, int *begin, int *size, int core_mask)
-
void c64_slice_s(float *input, float *output, int *input_shape, int ndim, int *begin, int *size, int core_mask)
-
void c128_slice_s(double *input, double *output, int *input_shape, int ndim, int *begin, int *size, int core_mask)
C调用示例:
1// FT78NE 示例(多核并行切片) 2#include <stdio.h> 3#include "78NE/utils.h" 4 5int main() { 6 float *input = (float *)0xA0000000; 7 float *output = (float *)0xB0000000; 8 int input_shape[] = {16, 32, 64, 128}; 9 int begin[] = {2, 4, 8, 16}; 10 int size[] = {8, 12, 20, 32}; 11 int ndim = 4; 12 int core_mask = 0xFF; // 使用8核并行 13 14 fp_slice_s(input, output, input_shape, ndim, begin, size, core_mask); 15 return 0; 16}
私有存储版本:
-
void i8_slice_p(int8_t *input, int8_t *output, int *input_shape, int ndim, int *begin, int *size)
-
void i16_slice_p(int16_t *input, int16_t *output, int *input_shape, int ndim, int *begin, int *size)
-
void i32_slice_p(int32_t *input, int32_t *output, int *input_shape, int ndim, int *begin, int *size)
-
void hp_slice_p(half *input, half *output, int *input_shape, int ndim, int *begin, int *size)
-
void fp_slice_p(float *input, float *output, int *input_shape, int ndim, int *begin, int *size)
-
void dp_slice_p(double *input, double *output, int *input_shape, int ndim, int *begin, int *size)
-
void c64_slice_p(float *input, float *output, int *input_shape, int ndim, int *begin, int *size)
-
void c128_slice_p(double *input, double *output, int *input_shape, int ndim, int *begin, int *size)
C调用示例:
1// MT7004 示例(单核私有存储切片) 2#include <stdio.h> 3 4int main() { 5 float *input = (float *)0x10000000; 6 float *output = (float *)0x10010000; 7 int input_shape[] = {4, 8, 16, 32}; 8 int begin[] = {1, 2, 3, 4}; 9 int size[] = {2, 3, 6, 8}; 10 int ndim = 4; 11 12 fp_slice_p(input, output, input_shape, ndim, begin, size); 13 return 0; 14}